package myaction.admin.courseinfo;

import myutil.DbUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;

public class AdminCoursesUpdateAction extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String c_id = request.getParameter("c_id");
        String c_name = request.getParameter("c_name");
        String c_time = request.getParameter("c_time");
        String c_teacher_id = request.getParameter("c_teacher_id");
        String c_isable = request.getParameter("c_isable");
        try {
            Connection conn = DbUtil.getConn();
            String sql = "update t_courses set c_name=?,c_time=?,c_teacher_id=?,c_isable=? where c_id=?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, c_name);
            ps.setString(2, c_time);
            ps.setString(3, c_teacher_id);
            ps.setString(4, c_isable);
            ps.setInt(5, Integer.parseInt(c_id));
            ps.executeUpdate();
            ps.close();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        response.sendRedirect("AdminCoursesFindAll");
    }
}
